package com.manatee.adnet;
import java.io.*;
import java.net.URL;
import java.nio.charset.Charset;

import org.json.JSONException;
import org.json.JSONObject;

import com.manatee.commercailapp.*;
import com.example.commercailapp.R;

import android.os.AsyncTask;
import android.widget.*;

public class MainActivityLib {
	private static MainActivityLib instance = null;
	protected MainActivityLib() {
	      // Exists only to defeat instantiation.
	}
	public static MainActivityLib getInstance() {
	   if(instance == null) {
	      instance = new MainActivityLib();
	   }
	   return instance;
	}
	
	
	   
	
    public String getCommercial(String url) throws IOException, JSONException{
    	return readJsonFromUrl(url);
    	
    }
    
    public String readJsonFromUrl(String urlString) throws IOException, JSONException {
    	
    	BufferedReader reader = null;
        try {
            URL url = new URL(urlString);

            reader = new BufferedReader(new InputStreamReader(url.openStream()));
            StringBuffer buffer = new StringBuffer();
            int read;
            char[] chars = new char[1024];
            while ((read = reader.read(chars)) != -1)
                buffer.append(chars, 0, read); 

            return buffer.toString();
        } finally {
            if (reader != null)
                reader.close();
        }
      }
    
    private String readAll(Reader rd) throws IOException {
        StringBuilder sb = new StringBuilder();
        int cp;
        while ((cp = rd.read()) != -1) {
          sb.append((char) cp);
        }
        return sb.toString();
      }
	
    
    /*
    public void main(){
    	
    	AdNet adnet = AdNet.getInstance();
    	adnet.getCommercial();
    	adnet.showCommercial();
    	
    	
    }
    
    */

}
